/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 * 
 * 执行时间: 120ms
 * 内存消耗: 38.1MB
 */
var twoSum = function(nums, target) {
  if (!(nums && Array.isArray(nums) && nums.length)) return 0;
  const length = nums.length;
  for (let i = 0; i < length - 1; i ++) {
    for (let j = i + 1; j < length; j ++) {
      if (nums[i] + nums[j] === target) {
        return [i, j];
      }
    }
  }
  return 0;
};

// test
const nums = [2, 7, 1, 1, 11, 15];
const target = 2;
console.log(twoSum(nums, target))